- Buy Microsoft Visio Professional or Microsoft Project Professional 2024 for just $80
- Get Microsoft Office Pro and Windows 11 Pro for 87% off with this bundle
- Buy or gift a Babbel subscription for 78% off to learn a new language - new low price
- Join BJ's Wholesale Club for just $20 right now to save on holiday shopping
- This $28 'magic arm' makes taking pictures so much easier (and it's only $20 for Black Friday)
Linux “Grep” && Windows “Findstr”
1. Filter a result
1.1 Classic example to filter a listing result.
#Linux
$ ls -ls | grep mkyong
#Windows
c:\> dir | findstr mkyong
1.2 Add ignore case, and filter the listing result with multiple strings.
#Linux – Need ‘-E’ option and Uses “|” to separate multiple search strings.
$ ls -ls | grep -iE “mkyong|music”
#Windows – Use spaces to separate multiple search strings
c:\> dir | findstr -i “mkyong music”
2. Search a File
2.1 Search matched string in a file.
#Linux
$ grep mkyong test.txt
#Windows
c:\> findstr mkyong test.txt
2.2 Counting the number of matches.
#Linux
$ grep -c mkyong test.txt
#Windows – Piped with find /c command.
c:\> findstr -N “mkyong” test.txt | find /c “:”
3. Search a list of files
3.1 Search matched string in a list of files.
#Linux
$ grep mkyong -lr /path/folder
#Windows
c:\> findstr /M mkyong c:\folder\*
* (grep) -l , (findstr) /M = print only name of files containing matches.